package com.drpclub.gamebackend.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @author ：drp
 * @date ：Created in 2020/5/7 23:54
 * @description：
 * @modified By：
 * @version: $
 */
@Configuration
public class CorsConfigure {
    private CorsConfiguration corsConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration ();
        corsConfiguration.addAllowedOrigin ("http://localhost:8080");
        corsConfiguration.addAllowedOrigin ("dongrp.club");
        corsConfiguration.addAllowedOrigin ("www.dongrp.club");
        corsConfiguration.addAllowedHeader (CorsConfiguration.ALL);
        corsConfiguration.addAllowedMethod (CorsConfiguration.ALL);
        corsConfiguration.setAllowCredentials (true);
        return corsConfiguration;
    }

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
        source.registerCorsConfiguration ("/**", corsConfig ());
        return new CorsFilter (source);
    }
}
